﻿using UnityEngine;
using System.Collections;
using Battle.View;

namespace Battle
{
    public class EnemyHeroInfo : MonoBehaviour
    {
        protected BattleCharacter current;

        public UI.TextureKit header;
        public UILabel nameLabel;
        public SmoothBar hpBar;
        #region
        public TweenPosition tweenPos;
        public TweenAlpha tweenAlpha;
        #endregion

        public virtual void SetCharactor(BattleCharacter charactor)
        {
            if(current == charactor)
            {
                hpBar.SetValue((int)charactor.hp, (int)charactor.maxHp);
            }
            else
            {
                current = charactor;
                hpBar.Init(Mathf.RoundToInt((float)charactor.hp), (int)charactor.maxHp);
                if (header != null)
                {
                    header.textureName = current.iconName;
                }
                nameLabel.text = current.heroName;
                tweenPos.ResetToBeginning();
                tweenPos.PlayForward();
                tweenAlpha.ResetToBeginning();

                StopAllCoroutines();
                HideDeadEffect();

            }
            gameObject.SetActive(true);
        }

        public void Dead(BattleCharacter bc) {
            if (bc == current && gameObject.activeSelf)
            {
                DeadHide();
            }
        }

        void DeadHide() {
            tweenAlpha.PlayForward();
        }

        /*
        IEnumerator DeadHide(float duration) {
            yield return new WaitForSeconds(duration);
            tweenAlpha.PlayForward();
            yield return new WaitForSeconds(tweenAlpha.duration);
            Hide();
        }
        */

        public void Hide()
        {
            current = null;
            gameObject.SetActive(false);
        }

        public void ShowDeadEffect() { }
        public void HideDeadEffect() { }
    }
}